Repository navigation
fix: Offer to reset a local database that a crash left unable to start. - #16
Merged
Merged
Conversation
A new project on Windows stopped being able to start its server: Postgres
refused postgresql.conf on every start ("syntax error ... line 1, near token
"""), and Try Again failed the same way each time. That message is what
Postgres prints for a configuration file that starts with NUL bytes. The
Serverpod CLI creates the cluster with initdb --no-sync and rewrites the
file unflushed, so a computer that crashes or loses power soon after a
project's first start can come back with it zero-filled, and the CLI never
recreates the cluster.
- After any failed start or runner exit, findDamagedDatabases reads the
cluster's text files under .serverpod/<mode>/pgdata and reports a data
directory when one of them holds a NUL byte.
- The status then reads "Database error", the log explains what happened,
and Reset Database takes Try Again's place. It asks first, deletes what
EmbeddedPostgres.reset() deletes, and starts the server, which creates the
database again and applies the migrations. The damage is looked for again
at that moment, so an intact database is never deleted.
- A stopped status message is capped at what the actions' icon form leaves,
so a longer one ellipsizes instead of overflowing the toolbar.
- specs/embedded_postgres_zeroed_conf_report.md has the analysis and the
report for Serverpod.
Only the zero-filled postgresql.conf was reproduced, with the bundled
Postgres parsing a test file; that the affected machine's file is zero-filled
is inferred from its error message. The reset was tested against files in a
scratch project, not against a real cluster and runner. The process-tagged
controller tests were not run on the Windows dev laptop.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…erverpod/serverpod#6081). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A new project on Windows stopped being able to start its server. Postgres refused
postgresql.confon every start (syntax error … line 1, near token ""), and Try Again failed the same way each time. That message is what Postgres prints for a configuration file that starts with NUL bytes. The Serverpod CLI creates the cluster withinitdb --no-syncand rewrites the file unflushed, so a computer that crashes or loses power soon after a project's first start can come back with it zero-filled, and the CLI never recreates the cluster.Reported upstream as serverpod/serverpod#6081; serverpod/serverpod#5996 is an earlier case of the same message. This PR is App Studio's way out for the user in the meantime.
What changes
findDamagedDatabasesreads the cluster's text files (PG_VERSION,postgresql.conf,pg_hba.conf,pg_ident.conf) under<server>/.serverpod/<mode>/pgdataand reports a data directory when one of them holds a NUL byte. It reads the disk, not the log, so it does not depend on the CLI's wording.EmbeddedPostgres.reset()deletes (the data directory,runbeside it, and the pid, log, state and password files), then starts the server, which creates the database again and applies the migrations. The damage is looked for again at that moment, so an intact database is never deleted.AGENTS.md, andspecs/embedded_postgres_zeroed_conf_report.mdwith the analysis and the upstream report.Verification
flutter analyzeis clean, andflutter test -x process -j 1passes on the Windows dev laptop (920 passed, 16 skipped).test/runner/runner_postgres_test.dart), the controller's side (test/process/database_reset_test.dart, not taggedprocesssince every start in it fails before a runner exists), and the toolbar and dialog (test/ui/studio_toolbar_test.dart). Widgetbook has a "Database damaged" window and the dialog.Not verified
postgresql.confwas reproduced, by having the bundled Postgres parse a test file. That the affected machine's file is zero-filled is inferred from its error message; the other three files are included by the same reasoning.database.dataPathpoints outside.serverpod/<mode>is not covered.🤖 Generated with Claude Code